import { v4 as UUID } from 'uuid';

export class Tools {
    static GetGuid() {
        return UUID().replace(/-/g, '');
    }

    static cloneArrary<T>(list: T[], excludes?: string[]): T[] {
        let t = [];

        list.forEach(item => {
            t.push(Tools.cloneObj(item, excludes))
        })

        return t;
    }

    static cloneObj(obj: Object, excludes?: string[]) {
        let newObj = {};
        for (let key in obj) {
            if (excludes) {
                let has = excludes.find(x => x == key);
                if (has) {
                    continue;
                }
            }

            if (obj[key] instanceof Array) {
                newObj[key] = Tools.cloneArrary(obj[key], excludes);
            }
            else {
                if (typeof (obj[key]) == "object") {
                    newObj[key] = Tools.cloneObj(obj[key], excludes);
                }
                else {
                    newObj[key] = obj[key];
                }
            }
        }

        return newObj;
    }

    static getRandColor() {
        const colors = [
            '#6690FF',
            '#ADC8FF',
            '#6ED268',
            '#5ACF78',
            '#76BBFB',
            '#B6E2FE',
            '#FFC275',
            '#FFDF8B',
            '#FF7471',
            '#FFC2B3',
            '#FFDB6B',
            '#FFE588',
            '#7675DC',
            '#B0AFF4',
            '#F57ECB',
            '#FDBBD9'
        ];

        const index = randomNum(0, colors.length - 1);
        return colors[index];
    }
}

function randomNum(minNum, maxNum) {
    switch (arguments.length) {
        case 1:
            return parseInt((Math.random() * minNum + 1) as any, 10);
            break;
        case 2:
            return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
            break;
        default:
            return 0;
            break;
    }
} 